﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ASKM.Rachao.Model;
using System.Web.Routing;

namespace ASKM.Rachao.Web.Site.Controllers
{ 
    [Authorize]
    public class PlayerProfileController : Controller
    {
        private RachaoEntities db = new RachaoEntities();

        //
        // GET: /PlayerProfile/

        public ViewResult Index()
        {
            return View(db.PlayerProfile.ToList());
        }

        public ActionResult InitialRegister(string ticket)
        {            
            using(var facade = new ASKM.Rachao.Model.Facade.Profile())
            {
                var pid = facade.ReleaseTicket(ticket);
                RouteValueDictionary rvd = new RouteValueDictionary();
                rvd.Add("id", pid);
                return RedirectToAction("Details", rvd);
            }                        
        }

        //
        // GET: /PlayerProfile/Details/5

        public ViewResult Details(int id)
        {
            PlayerProfile playerprofile = db.PlayerProfile.Find(id);
            return View(playerprofile);
        }

        //
        // GET: /PlayerProfile/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /PlayerProfile/Create

        [HttpPost]
        public ActionResult Create(PlayerProfile playerprofile)
        {
            if (ModelState.IsValid)
            {
                db.PlayerProfile.Add(playerprofile);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(playerprofile);
        }
        
        //
        // GET: /PlayerProfile/Edit/5
 
        public ActionResult Edit(int id)
        {
            PlayerProfile playerprofile = db.PlayerProfile.Find(id);
            return View(playerprofile);
        }

        //
        // POST: /PlayerProfile/Edit/5

        [HttpPost]
        public ActionResult Edit(PlayerProfile playerprofile)
        {
            if (ModelState.IsValid)
            {
                db.Entry(playerprofile).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(playerprofile);
        }

        //
        // GET: /PlayerProfile/Delete/5
 
        public ActionResult Delete(int id)
        {
            PlayerProfile playerprofile = db.PlayerProfile.Find(id);
            return View(playerprofile);
        }

        //
        // POST: /PlayerProfile/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            PlayerProfile playerprofile = db.PlayerProfile.Find(id);
            db.PlayerProfile.Remove(playerprofile);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}